/**
 * 
 */
package com.hexacta.hrs.repositories.impl;

import java.util.Collection;

import org.hibernate.criterion.Example;
import org.hibernate.criterion.MatchMode;
import org.vectrics.recruiter.job.JobCandidate;

/**
 * @author mfunes
 *
 */
public class JobCandidateRecordObjectRepository extends HibernateRecordObjectRepository<JobCandidate> {

    public JobCandidateRecordObjectRepository(Class<JobCandidate> entityClass) {
        super(entityClass);
    }

    /** {@inheritDoc} */
    @SuppressWarnings("unchecked")
    @Override
    public Collection<JobCandidate> matching(JobCandidate criteria) {
        if(criteria.getCandidate()==null)
            return super.matching(criteria);
        Example exampleJobCandidate = Example.create(criteria).ignoreCase().enableLike(MatchMode.ANYWHERE);
        Example exampleCandidate = Example.create(criteria.getCandidate()).ignoreCase().enableLike(MatchMode.ANYWHERE);       
        return  getSession().createCriteria(JobCandidate.class).add(exampleJobCandidate).createCriteria("candidate").add(exampleCandidate).list();
    }
}
